angular.module('imsApp').controller('advManagementDetailModalController', ['$scope','$state', 'AdvManagementManager','$uibModalInstance','campaigns', function ($scope,$state, AdvManagementManager,$uibModalInstance,campaigns) {
    $scope.campaignsId = campaigns.campaignId;
    $scope.campaignId = campaigns.campaignsId;
    $scope.formData={};
    $scope.advManagement={type:410};

    $scope.ok = function () {
        saveAdvManagementData();

    };
    var date=campaigns.startEndDay;
    var dateArr= date.split("~");
   $scope.formData=campaigns;

    $scope.cancel = function () {
        $uibModalInstance.dismiss("cancel");
    };
    $scope.rangeDate = {
        startDate:moment(dateArr[0]).format('X'),
        endDate: moment(dateArr[1]).format('X'),
        onSelected: function (data, scope) {  //时间选择确认事件
            var startDay =data.startDate? moment(new Date(parseFloat(data.startDate) * 1000)).format("YYYY-MM-DD"):null;
            var endDay = data.endDate?moment(new Date(new Date(parseFloat(data.endDate) * 1000))).format("YYYY-MM-DD"):null;
            $scope.formData.startEndDay=startDay+"~" +endDay
        }
    };
    $scope.submited=false;
    var saveAdvManagementData=function () {
        $scope.submited=true;
        if($scope.formData.campaignName){
            if( $scope.formData.startEndDay!='null~null'){
                AdvManagementManager.campaignsEdit($scope.campaignsId,$scope.formData).then(function (result) {
                    if(result.data.c=='s'){
                        $uibModalInstance.close("ok");
                    }else{
                        $uibModalInstance.close("error");
                    }
                });
            }
        }
    }
    $scope.delete = function (size) {
        ImsDialog.open({title:"删除确认",message:"您确定要删除该条数据吗?"}).then(function (a) {
            if(a=='ok'){
            }else{

            }
        })
    };

}])

